IF EXISTS (
       SELECT *
       FROM   sys.objects
       WHERE  OBJECT_ID = OBJECT_ID(N'[dbo].[cms_sp_MediaContentSelectOne]')
              AND TYPE IN (N'P' ,N'PC')
   )
    DROP PROCEDURE [dbo].[cms_sp_MediaContentSelectOne]
GO

CREATE PROCEDURE [dbo].[cms_sp_MediaContentSelectOne] 
(@Id INT)
AS
BEGIN
	SELECT mc.*
	      ,mc.[MediaContentId]  AS [Id]
	      ,l.MediaFileId        AS MainFile_Id
	FROM   MediaContents mc
	       LEFT JOIN (
	                SELECT *
	                FROM   MediaContentFileLinks
	                WHERE  IsPrimary = 1
	            ) l
	            ON  l.MediaContentId = mc.MediaContentId
	WHERE  mc.MediaContentId = @Id
END
GO